package case1

import "fmt"
import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func Test() {
	fmt.Println("🎯示例一：连接Mysql")

	db := mysqlConnect()
	fmt.Println(db)

}

// 初始化连接
func mysqlConnect() *gorm.DB {
	// 连接字符串
	var url string = "root:123456@tcp(127.0.0.1:3306)/case1?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(url), &gorm.Config{})
	if err != nil {
		fmt.Println("连接失败...")
	}
	fmt.Println("连接成功...")
	return db
}
